package com.gobo.eduservice.controller;


import com.gobo.commonutils.R;
import com.gobo.eduservice.pojo.EduChapter;
import com.gobo.eduservice.pojo.EduVideo;
import com.gobo.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author gobo-generator
 * @since 2021-09-19
 */
@RestController
@RequestMapping("/eduservice/video")
public class EduVideoController {

    @Autowired
    private EduVideoService videoService;

    //通过Id查询小节信息
    @GetMapping("/getVideo/{videoId}")
    public R getVideoById(@PathVariable String videoId){
        EduVideo eduVideo = videoService.getById(videoId);
        return R.ok().data("item",eduVideo);
    }

    //通过Id删除小节
    @PostMapping("/delete/{videoId}")
    public R deleteVideoById(@PathVariable String videoId){
        boolean b = videoService.removeVideoAndSourceById(videoId);
        return b?R.ok():R.error();
    }

    //增加
    @PostMapping("/save")
    public R saveVideo(@RequestBody EduVideo eduVideo){
        boolean save = videoService.save(eduVideo);
        return save?R.ok():R.error();
    }
    //修改
    @PostMapping("/update")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        boolean update = videoService.updateById(eduVideo);
        return update?R.ok():R.error();
    }

}

